home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / PROGRAMM / DB_CLIPP / 2510.ZIP / TRSOURCE.EXE / DEPSL.C < prev    next >
C/C++ Source or Header  |  1990-10-22  |  2KB  |  54 lines

  1. /*********
  2. *
  3. * DEPSL.C
  4. *
  5. * by Ralph Davis
  6. * modified by Tom Rettig
  7. *
  8. * Placed in the public domain by Tom Rettig Associates, 10/22/1990.
  9. *
  10. *********/
  11.  
  12. /* DEPSL:  Depreciation by straight-line method
  13.  
  14.             Computes depreciation by subtracting anticipated
  15.                  resale price of an asset from its original
  16.                  purchase price and dividing by its anticipated
  17.                  time of usage.
  18.  
  19.             For example:  IBM PC AT purchased at $5000.
  20.                           Anticipated final sale price $1000.
  21.                           Anticipated time of service 5 years.
  22.                           Time currently in service 2 years.
  23.                
  24.                           Depreciation = (5000-1000)/5 
  25.                                        = $800 / year
  26.                                          * 2 years = $1600
  27.             SYNTAX:  DEPSL(purchase, resale, total periods, periods to date)
  28.      
  29.                      where  purchase = initial price
  30.                             resale   = anticipated resale value
  31.                       total periods  = time periods in service life
  32.                     periods to date  = number of periods involved
  33.                                        in calculation
  34.             RETURNS:  Depreciation
  35. */
  36.  
  37. #include "trlib.h"
  38.  
  39. TRTYPE depsl()
  40. {
  41.    if ( PCOUNT==4 && ISNUM(1) && ISNUM(2) && ISNUM(3) && ISNUM(4) )
  42.    {
  43.        double purchase = _parnd(1);
  44.        double resale   = _parnd(2);
  45.        int    totper  = (int)_parnd(3);
  46.        int    periods = (int)_parnd(4);
  47.    
  48.        _retnd( (periods>=totper) ? purchase :
  49.                                    periods * ((purchase - resale) / totper));
  50.    }
  51.    else
  52.       _retnd( (double)ERROR );
  53. }
  54.